from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-09-13 14:12:57.716465
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 13, Sep, 2021
Time: 14:13:03
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -46.1434
Nobs: 413.000 HQIC: -46.6734
Log likelihood: 4525.47 FPE: 3.79701e-21
AIC: -47.0202 Det(Omega_mle): 3.06146e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.436862 0.093158 4.689 0.000
L1.Burgenland 0.106029 0.048286 2.196 0.028
L1.Kärnten -0.114113 0.024027 -4.749 0.000
L1.Niederösterreich 0.162956 0.103443 1.575 0.115
L1.Oberösterreich 0.121575 0.101286 1.200 0.230
L1.Salzburg 0.284947 0.050586 5.633 0.000
L1.Steiermark 0.024333 0.067020 0.363 0.717
L1.Tirol 0.108386 0.052968 2.046 0.041
L1.Vorarlberg -0.111218 0.047659 -2.334 0.020
L1.Wien -0.012763 0.092314 -0.138 0.890
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.014824 0.215080 0.069 0.945
L1.Burgenland -0.046024 0.111481 -0.413 0.680
L1.Kärnten 0.037620 0.055473 0.678 0.498
L1.Niederösterreich -0.214780 0.238825 -0.899 0.368
L1.Oberösterreich 0.487217 0.233845 2.084 0.037
L1.Salzburg 0.305485 0.116791 2.616 0.009
L1.Steiermark 0.113556 0.154732 0.734 0.463
L1.Tirol 0.314193 0.122291 2.569 0.010
L1.Vorarlberg 0.003049 0.110033 0.028 0.978
L1.Wien -0.003596 0.213132 -0.017 0.987
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.248737 0.047404 5.247 0.000
L1.Burgenland 0.089963 0.024571 3.661 0.000
L1.Kärnten -0.001704 0.012226 -0.139 0.889
L1.Niederösterreich 0.208104 0.052638 3.954 0.000
L1.Oberösterreich 0.167633 0.051540 3.252 0.001
L1.Salzburg 0.033900 0.025741 1.317 0.188
L1.Steiermark 0.019822 0.034103 0.581 0.561
L1.Tirol 0.066848 0.026953 2.480 0.013
L1.Vorarlberg 0.059769 0.024251 2.465 0.014
L1.Wien 0.108675 0.046975 2.313 0.021
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.181490 0.046333 3.917 0.000
L1.Burgenland 0.049102 0.024015 2.045 0.041
L1.Kärnten -0.006656 0.011950 -0.557 0.578
L1.Niederösterreich 0.136057 0.051448 2.645 0.008
L1.Oberösterreich 0.317233 0.050375 6.297 0.000
L1.Salzburg 0.100775 0.025159 4.005 0.000
L1.Steiermark 0.132697 0.033333 3.981 0.000
L1.Tirol 0.075311 0.026344 2.859 0.004
L1.Vorarlberg 0.057322 0.023703 2.418 0.016
L1.Wien -0.043660 0.045913 -0.951 0.342
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.209516 0.091964 2.278 0.023
L1.Burgenland -0.055332 0.047667 -1.161 0.246
L1.Kärnten -0.034984 0.023719 -1.475 0.140
L1.Niederösterreich 0.113199 0.102117 1.109 0.268
L1.Oberösterreich 0.170977 0.099987 1.710 0.087
L1.Salzburg 0.255890 0.049938 5.124 0.000
L1.Steiermark 0.079231 0.066160 1.198 0.231
L1.Tirol 0.124358 0.052289 2.378 0.017
L1.Vorarlberg 0.115194 0.047048 2.448 0.014
L1.Wien 0.026318 0.091131 0.289 0.773
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.028654 0.071303 0.402 0.688
L1.Burgenland 0.024703 0.036958 0.668 0.504
L1.Kärnten 0.052229 0.018390 2.840 0.005
L1.Niederösterreich 0.210180 0.079174 2.655 0.008
L1.Oberösterreich 0.336323 0.077524 4.338 0.000
L1.Salzburg 0.044980 0.038718 1.162 0.245
L1.Steiermark -0.005872 0.051296 -0.114 0.909
L1.Tirol 0.113356 0.040542 2.796 0.005
L1.Vorarlberg 0.065821 0.036478 1.804 0.071
L1.Wien 0.130381 0.070657 1.845 0.065
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185948 0.087305 2.130 0.033
L1.Burgenland 0.019157 0.045252 0.423 0.672
L1.Kärnten -0.057324 0.022517 -2.546 0.011
L1.Niederösterreich -0.112569 0.096943 -1.161 0.246
L1.Oberösterreich 0.187561 0.094922 1.976 0.048
L1.Salzburg 0.030918 0.047408 0.652 0.514
L1.Steiermark 0.300486 0.062808 4.784 0.000
L1.Tirol 0.485844 0.049640 9.787 0.000
L1.Vorarlberg 0.069726 0.044664 1.561 0.118
L1.Wien -0.106854 0.086514 -1.235 0.217
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.159698 0.094919 1.682 0.092
L1.Burgenland -0.006365 0.049199 -0.129 0.897
L1.Kärnten 0.061723 0.024481 2.521 0.012
L1.Niederösterreich 0.184460 0.105398 1.750 0.080
L1.Oberösterreich -0.127436 0.103201 -1.235 0.217
L1.Salzburg 0.235778 0.051542 4.574 0.000
L1.Steiermark 0.159062 0.068287 2.329 0.020
L1.Tirol 0.052014 0.053970 0.964 0.335
L1.Vorarlberg 0.125692 0.048560 2.588 0.010
L1.Wien 0.158040 0.094059 1.680 0.093
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.486287 0.051469 9.448 0.000
L1.Burgenland -0.010643 0.026678 -0.399 0.690
L1.Kärnten -0.009842 0.013275 -0.741 0.458
L1.Niederösterreich 0.207204 0.057151 3.626 0.000
L1.Oberösterreich 0.262089 0.055959 4.684 0.000
L1.Salzburg 0.023261 0.027948 0.832 0.405
L1.Steiermark -0.025206 0.037028 -0.681 0.496
L1.Tirol 0.066442 0.029264 2.270 0.023
L1.Vorarlberg 0.056593 0.026331 2.149 0.032
L1.Wien -0.053079 0.051003 -1.041 0.298
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.021140 0.080053 0.141251 0.133775 0.040596 0.073718 -0.003468 0.175977
Kärnten 0.021140 1.000000 -0.045358 0.126879 0.046472 0.070231 0.455246 -0.094489 0.091930
Niederösterreich 0.080053 -0.045358 1.000000 0.285352 0.081397 0.266803 0.022230 0.138650 0.261736
Oberösterreich 0.141251 0.126879 0.285352 1.000000 0.180746 0.285363 0.157044 0.099328 0.139740
Salzburg 0.133775 0.046472 0.081397 0.180746 1.000000 0.127242 0.055347 0.104730 0.048994
Steiermark 0.040596 0.070231 0.266803 0.285363 0.127242 1.000000 0.130975 0.088496 -0.024289
Tirol 0.073718 0.455246 0.022230 0.157044 0.055347 0.130975 1.000000 0.038387 0.117182
Vorarlberg -0.003468 -0.094489 0.138650 0.099328 0.104730 0.088496 0.038387 1.000000 -0.048415
Wien 0.175977 0.091930 0.261736 0.139740 0.048994 -0.024289 0.117182 -0.048415 1.000000